home *** CD-ROM | disk | FTP | other *** search
/ Mac Expert 1995 Winter / Mac Expert - Winter 95.iso / Les fichiers / Communications / Internet / TurboTCP 2.1 ƒ / TCL MiniTelnet source / CMiniTelnetApp.cp next >
Encoding:
Text File  |  1995-01-04  |  7.1 KB  |  373 lines  |  [TEXT/MMCC]

  1. /*
  2. ** CMiniTelnetApp.cp
  3. **
  4. **    MiniTelnet application
  5. **    Application subclass
  6. **
  7. **    Copyright © 1993-94, FrostByte Design / Eric Scouten
  8. **
  9. */
  10.  
  11.  
  12. #include "CMiniTelnetApp.h"
  13.  
  14. #include "CArrowPopupPane.h"
  15. #include "CBartender.h"
  16. #include "CDataFile.h"
  17. #include "CDialogText.h"
  18. #include "CIconPane.h"
  19. #include "CPopupMenu.h"
  20. #include "CPopupPane.h"
  21. #include "CRadioControl.h"
  22. #include "CRadioGroupPane.h"
  23. #include "CStdPopupPane.h"
  24. #include "TBUtilities.h"
  25. #include "TCLForceReferences.h"
  26.  
  27. //#include "CAboutDirector.h"
  28. #include "CTelnetTerminal.h"
  29. #include "CTelnetSettingsDLOG.h"
  30.  
  31.  
  32. // global TCL objects
  33.  
  34. extern CApplication*    gApplication;
  35. extern CBartender*        gBartender;
  36. extern OSType            gSignature;
  37. extern CursHandle        gWatchCursor;
  38. extern OSType            gSignature;
  39.  
  40. TCL_DEFINE_CLASS_M1(CMiniTelnetApp, CTCPApplication);
  41.  
  42.  
  43. //    —— application startup ——
  44.  
  45. /*______________________________________________________________________
  46. **
  47. ** main()
  48. **
  49. **    The big one. Set up the OOP stuff and let it go.
  50. **
  51. */
  52.  
  53. void main()
  54.  
  55. {
  56.     CMiniTelnetApp* theApp = new CMiniTelnetApp;
  57.     theApp->Run();
  58.     theApp->Exit();
  59. }
  60.  
  61.  
  62. /*______________________________________________________________________
  63. **
  64. ** constructor
  65. **
  66. **    Initialize the application.
  67. **
  68. */
  69.  
  70. CMiniTelnetApp::CMiniTelnetApp()
  71.     : CTCPApplication(kExtraMasters, kRainyDayFund, kCriticalBalance, kToolboxBalance)
  72.  
  73. {
  74.     gSignature = kAppSignature;
  75. }
  76.  
  77. /*______________________________________________________________________
  78. **
  79. ** ForceClassReferences
  80. **
  81. **    Reference classes used by new_by_name.
  82. **
  83. */
  84.  
  85. void CMiniTelnetApp::ForceClassReferences()
  86.  
  87. {
  88.     TCL_FORCE_REFERENCE(CArrowPopupPane);
  89.     TCL_FORCE_REFERENCE(CDialogText);
  90.     TCL_FORCE_REFERENCE(CIconPane);
  91.     TCL_FORCE_REFERENCE(CPopupMenu);
  92. //    TCL_FORCE_REFERENCE(CPopupPane);
  93.     TCL_FORCE_REFERENCE(CRadioControl);
  94.     TCL_FORCE_REFERENCE(CRadioGroupPane);
  95.     TCL_FORCE_REFERENCE(CStdPopupPane);
  96. }
  97.  
  98.  
  99. //    —— creation of Telnet sessions (documents) ——
  100.  
  101. /*______________________________________________________________________
  102. **
  103. ** CreateDocument
  104. **
  105. **    What happens to File->New from the menu. Creates a settings dialog rather than a session
  106. **    document. The dialog will open a session if the user so desires.
  107. **
  108. */
  109.  
  110. void CMiniTelnetApp::CreateDocument()
  111.  
  112. {
  113.     CTelnetSettingsDLOG* theDialog = NULL;
  114.     
  115.     TRY {
  116.         theDialog = new CTelnetSettingsDLOG(this);
  117.         theDialog->DefaultSettings();
  118.         theDialog->BeginDialog();
  119.     }
  120.     
  121.     CATCH {
  122.         ForgetObject(theDialog);
  123.     }
  124.     ENDTRY;
  125. }
  126.  
  127.  
  128. /*______________________________________________________________________
  129. **
  130. ** OpenDocument
  131. **
  132. **    The user chose Open… from the File menu. Creates a new session
  133. **    with the contents of the settings file.
  134. **
  135. **        macSFReply (SFReply*):    the settings file document to open
  136. **
  137. */
  138.  
  139. void CMiniTelnetApp::OpenDocument(SFReply* macSFReply)
  140.  
  141. {
  142.     TelnetSettingsRec newSettings;
  143.  
  144.     if (macSFReply->fType == kSettingsFileType) {
  145.         OpenSettingsFile(macSFReply, &newSettings);
  146.         NewSession(&newSettings);
  147.     }
  148. }
  149.  
  150.  
  151. /*______________________________________________________________________
  152. **
  153. ** OpenSettings
  154. **
  155. **    What happens to File->Open Settings from the menu. Creates a new settings dialog with the
  156. **    contents of the settings file.
  157. **
  158. **        macSFReply (SFReply *):    the settings file document to open
  159. **
  160. */
  161.  
  162. void CMiniTelnetApp::OpenSettings(SFReply* macSFReply)
  163.  
  164. {
  165.     CTelnetSettingsDLOG*    theDialog = NULL;
  166.     TelnetSettingsRec        newSettings;
  167.     
  168.     OpenSettingsFile(macSFReply, &newSettings);
  169.  
  170.     TRY {
  171.         theDialog = new CTelnetSettingsDLOG(this);
  172.         BlockMove(&newSettings, &(theDialog->r), sizeof(TelnetSettingsRec));
  173.         theDialog->PutSettings();
  174.         theDialog->BeginDialog();
  175.     }
  176.     
  177.     CATCH {
  178.         ForgetObject(theDialog);
  179.     }
  180.     ENDTRY;
  181.     
  182. }
  183.  
  184.  
  185. /*______________________________________________________________________
  186. **
  187. ** OpenSettingsFile
  188. **
  189. **    Read a Telnet settings document.
  190. **
  191. **        macSFReply (SFReply*):            the settings file document to read
  192. **        theSettings (TelnetSettingsRec*):    where to put the settings record
  193. **
  194. */
  195.  
  196. void CMiniTelnetApp::OpenSettingsFile(SFReply* macSFReply, TelnetSettingsRec* theSettings)
  197.  
  198. {
  199.     CDataFile*    itsFile = NULL;                // don’t need to keep the file around
  200.  
  201.  
  202.     // read the file
  203.     
  204.     TRY {
  205.         itsFile = new CDataFile;
  206.         itsFile->SFSpecify(macSFReply);
  207.         itsFile->Open(fsRdPerm);
  208.         
  209.         itsFile->ReadSome((Ptr) theSettings, sizeof (TelnetSettingsRec));
  210.         itsFile->Close();
  211.         delete itsFile;
  212.     }
  213.     
  214.     CATCH {
  215.         ForgetObject(itsFile);
  216.     }
  217.     ENDTRY;
  218. }
  219.  
  220.  
  221. /*______________________________________________________________________
  222. **
  223. ** NewSession
  224. **
  225. **    Create a new session from the settings record given.
  226. **
  227. **        newSettings (TelnetSettingsRec*):    the settings record which was opened
  228. **
  229. */
  230.  
  231. void CMiniTelnetApp::NewSession(TelnetSettingsRec* newSettings)
  232.  
  233. {
  234.     CTelnetTerminal* newTerminal = new CTelnetTerminal(kTelnetPort, kTelnetRecBufferSize,
  235.                                                 kTelnetAutoRecSize, kTelnetAutoRecNum);
  236.     newTerminal->NewSession(newSettings);
  237.             // terminal session doc will dispose of itself if it fails
  238. }
  239.  
  240.  
  241. /*______________________________________________________________________
  242. **
  243. ** SetUpFileParameters
  244. **
  245. **    What kind of files can we handle?
  246. **
  247. */
  248.  
  249. void CMiniTelnetApp::SetUpFileParameters()
  250.  
  251. {
  252.     CApplication::SetUpFileParameters();
  253.  
  254.     sfNumTypes = 1;
  255.     sfFileTypes[0] = kSettingsFileType;
  256.     gSignature = kAppSignature;
  257. }
  258.  
  259.  
  260. //    —— menu/command handling ——
  261.  
  262. /*______________________________________________________________________
  263. **
  264. ** DoCommand
  265. **
  266. **    Handle application-specific commands.
  267. **
  268. **        theCommand (long):    the command number which was issued
  269. **
  270. */
  271.  
  272. void CMiniTelnetApp::DoCommand(long theCommand)
  273.  
  274. {
  275.     Point                corner;
  276.     SFTypeList        fileTypes;
  277.     SFReply            macSFReply;
  278. /*
  279.     CAboutDirector*    theAboutDirector = NULL;
  280. */
  281.  
  282.     switch (theCommand) {
  283.  
  284. /*
  285.         // About… command
  286.  
  287.         case cmdAbout:
  288.             theAboutDirector = new CAboutDirector(DLOGAboutBox, this);
  289.             theAboutDirector->DoAbout(FALSE, 0);
  290.             break;
  291. */        
  292.  
  293.  
  294.         // open settings file
  295.  
  296.         case cmdOpenSettings:
  297.                                 // can’t use ChooseFile since subclass might
  298.                                 // have specified additional file types
  299.             fileTypes[0] = kSettingsFileType;
  300.             FindDlogPosition('DLOG', sfGetDLOGid, &corner);
  301.             SFPGetFile(corner, "\p", sfFileFilter, 1, fileTypes,
  302.                         sfGetDLOGHook, &macSFReply, sfGetDLOGid, sfGetDLOGFilter);
  303.  
  304.             if (macSFReply.good) {
  305.                 SetCursor(*gWatchCursor);
  306.                 OpenSettings(&macSFReply);
  307.             }
  308.             break;
  309.         
  310.         default:
  311.             CTCPApplication::DoCommand(theCommand);
  312.             break;
  313.     }
  314. }
  315.  
  316.  
  317. /*______________________________________________________________________
  318. **
  319. ** SetUpMenus
  320. **
  321. **    Set up menus which must be created at run time.
  322. **
  323. */
  324.  
  325. void CMiniTelnetApp::SetUpMenus()
  326.  
  327. {
  328.     CTCPApplication::SetUpMenus();
  329.     gBartender->SetUnchecking(MENUTelnet, TRUE);
  330. }
  331.  
  332.  
  333. /*______________________________________________________________________
  334. **
  335. ** UpdateMenus
  336. **
  337. **    Adjust menus on mouse-down event.
  338. **
  339. */
  340.  
  341. void CMiniTelnetApp::UpdateMenus()
  342.  
  343. {
  344.     CApplication::UpdateMenus();
  345.     gBartender->EnableCmd(cmdOpenSettings);
  346. }
  347.  
  348.  
  349. /*______________________________________________________________________
  350. **
  351. ** Run
  352. **
  353. **    Run the application. Overriden to provide splash screen.
  354. **
  355. */
  356.  
  357. void CMiniTelnetApp::Run()
  358.  
  359. {
  360. /*
  361.     CAboutDirector*    theAboutDirector = NULL;
  362. */
  363.  
  364.     // show a splash screen (modified about… box), then run the app
  365.     
  366. /*
  367.     theAboutDirector = new CAboutDirector(DLOGAboutBox, this);
  368.     theAboutDirector->DoAbout(TRUE, kSplashScreenTicks);
  369. */
  370.  
  371.     CApplication::Run();
  372.  
  373. }